package com.zsp.test.randomIP;

import java.util.Random;

public class RandomIP {
    public static void main(String[] args) {
        System.out.println(generateRandomIP());
    }
    public static String generateRandomIP() {
        Random rand = new Random();
        int[] ranges = {256, 256, 256, 256}; // IP地址的每个组成部分的范围为0-255
        int[] segments = new int[4]; // 保存每个IP地址段的整数值
        // 生成每个 IP 地址段的随机整数
        for (int i = 0; i < segments.length; i++) {
            segments[i] = rand.nextInt(ranges[i]);
        }
        // 构造 IP 地址字符串
        return String.format("%d.%d.%d.%d", segments[0], segments[1], segments[2], segments[3]);
    }
}
